<script lang="ts">
/**
 * 侧边栏
 * @author lvk
 * @summary 可以收缩的侧边栏，控制收缩的变量存在pinia中，这边主要是写死的菜单
 * */
import { computed, defineComponent } from 'vue'
import { ArrowLeft, ArrowRight } from '@element-plus/icons-vue'
import IconFont from '@/libs/Iconfont/index.vue'
import useMainStore from '@/store/main'
import { storeToRefs } from 'pinia'
import { useRouter } from 'vue-router'

export default defineComponent({
  name: 'CompSide',
  components: {
    IconFont,
    IconAL: ArrowLeft,
    IconAR: ArrowRight,
  },
  setup() {
    const store = useMainStore()
    const { sideShrink: shrink } = storeToRefs(store)

    const router = useRouter()
    const currentPath = computed(() => router.currentRoute.value.path)

    function shrinkThePanel(flag?: boolean) {
      store.setSideShrink(flag)
    }

    return { shrink, currentPath, shrinkThePanel }
  },
})
</script>

<template>
  <aside class="aside">
    <div class="aside-full" :class="{ shrink }">
      <div class="aside-wrapper">
        <el-scrollbar height="100%">
          <div class="fake-block" style="height: 35px"></div>
          <!-- 侧边栏 -->
          <el-menu
            :default-active="currentPath"
            class="el-menu-vertical-demo"
            router
          >
            <el-sub-menu index="1">
              <template #title>
                <el-icon>
                  <icon-font type="i-weihu"></icon-font>
                </el-icon>
                <span>设备信息</span>
              </template>
              <el-menu-item-group>
                <el-sub-menu index="1-1">
                  <template #title>
                    <span>长源热电有限公司</span>
                  </template>
                  <el-menu-item index="/">
                    <span>6号汽轮机发电机组</span>
                  </el-menu-item>
                </el-sub-menu>
                <el-sub-menu index="1-2">
                  <template #title>
                    <span>华鲁恒升</span>
                  </template>
                  <el-menu-item index="/power">
                    <span>动力岛C01</span>
                  </el-menu-item>
                </el-sub-menu>
                <el-sub-menu index="1-3">
                  <template #title>
                    <span>华南宏耀环保能源有限公司</span>
                  </template>
                  <el-menu-item index="/backpressure">
                    <span style="line-height: 1.1">
                      10MW高温高压非可调<br />抽汽背压式汽轮机
                    </span>
                  </el-menu-item>
                </el-sub-menu>
              </el-menu-item-group>
            </el-sub-menu>
          </el-menu>
          <!-- 侧边栏结束 -->
          <div class="fake-block" style="height: 35px"></div>
        </el-scrollbar>
      </div>
      <div class="aside-footer">
        <button type="button" class="shrink-btn" @click="shrinkThePanel(true)">
          <el-icon>
            <IconAL />
          </el-icon>
        </button>
      </div>
    </div>
    <div
      class="aside-shrink"
      :class="{ shrink }"
      @click="shrinkThePanel(false)"
    >
      <el-icon>
        <IconAR />
      </el-icon>
    </div>
  </aside>
</template>

<style lang="scss" scoped>
.aside {
  position: relative;
  height: 100%;
  background: var(--panel-color);
  border-radius: 0 var(--common-radius) var(--common-radius) 0;
}

.aside-full {
  position: relative;
  z-index: 1;
  width: 490px;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all 0.25s ease-in-out;

  &.shrink {
    width: 33px;
    opacity: 0;
    pointer-events: none;
  }
}

.aside-shrink {
  position: absolute;
  z-index: 2;
  top: 0;
  left: 0;
  cursor: pointer;
  width: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 30px;
  transition: all 0.25s ease-in-out;
  opacity: 0;

  &.shrink {
    width: 33px;
    opacity: 1;
  }
}

.aside-wrapper {
  height: 100%;
  padding: 0 24px 0 16px;
}

.aside-footer {
  height: 130px;
  flex-shrink: 0;
  border-top: 2px solid #fff;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.image-icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  background: url('/images/设备.png') center/contain no-repeat;
  margin-right: 5px;
}
</style>
